import 'package:flutter/widgets.dart';

class CoreTranslation {
  static LocalizationsDelegate<CoreTranslation> delegate = _CoreTranslationDelegate();

  static CoreTranslation of(BuildContext context) {
    return Localizations.of(context, CoreTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get ok {
    return _resolve(const {
      'ru': 'ОК',
      'en': 'OK',
    });
  }

  String get navigationBarCreateButtonTitle {
    return _resolve(const {
      'ru': 'Создать',
      'en': 'Create',
    });
  }

  String get navigationBarAddButtonTitle {
    return _resolve(const {
      'ru': 'Добавить',
      'en': 'Add',
    });
  }

  String get navigationBarDoneButtonTitle {
    return _resolve(const {
      'ru': 'Готово',
      'en': 'Done',
    });
  }

  String get navigationBarRemoveButtonTitle {
    return _resolve(const {
      'ru': 'Удалить',
      'en': 'Remove',
    });
  }

  String get navigationBarDeleteButtonTitle {
    return _resolve(const {
      'ru': 'Удалить',
      'en': 'Delete',
    });
  }

  String get navigationBarCancelButtonTitle {
    return _resolve(const {
      'ru': 'Отменить',
      'en': 'Cancel',
    });
  }

  String get actionDialogCancelButtonTitle {
    return _resolve(const {
      'ru': 'Отменить',
      'en': 'Cancel',
    });
  }

  String get premiumBadgeTitle {
    return _resolve(const {
      'ru': 'PRO',
      'en': 'PRO',
    });
  }
}

class _CoreTranslationDelegate extends LocalizationsDelegate<CoreTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<CoreTranslation> old) => false;

  @override
  Future<CoreTranslation> load(Locale locale) async {
    final translation = CoreTranslation();
    await translation.load(locale);
    return translation;
  }
}
